package com.itheima.service.impl;

import com.itheima.dao.GenTableColumnDao;
import com.itheima.pojo.GenTableColumn;
import com.itheima.service.GenTableColumnService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * (GenTableColumn)表服务实现类
 *
 * @author makejava
 * @since 2022-01-16 15:48:51
 */
@Service("genTableColumnService")
public class GenTableColumnServiceImpl implements GenTableColumnService {
    @Resource
    private GenTableColumnDao genTableColumnDao;

    /**
     * 通过ID查询单条数据
     *
     * @param columnId 主键
     * @return 实例对象
     */
    @Override
    public GenTableColumn queryById(Long columnId) {
        return this.genTableColumnDao.queryById(columnId);
    }

    /**
     * 分页查询
     *
     * @param genTableColumn 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<GenTableColumn> queryByPage(GenTableColumn genTableColumn, PageRequest pageRequest) {
        long total = this.genTableColumnDao.count(genTableColumn);
        return new PageImpl<>(this.genTableColumnDao.queryAllByLimit(genTableColumn, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param genTableColumn 实例对象
     * @return 实例对象
     */
    @Override
    public GenTableColumn insert(GenTableColumn genTableColumn) {
        this.genTableColumnDao.insert(genTableColumn);
        return genTableColumn;
    }

    /**
     * 修改数据
     *
     * @param genTableColumn 实例对象
     * @return 实例对象
     */
    @Override
    public GenTableColumn update(GenTableColumn genTableColumn) {
        this.genTableColumnDao.update(genTableColumn);
        return this.queryById(genTableColumn.getColumnId());
    }

    /**
     * 通过主键删除数据
     *
     * @param columnId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long columnId) {
        return this.genTableColumnDao.deleteById(columnId) > 0;
    }
}
